﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Expenses.Views.ExpenseReportsHistoryPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Expenses.Views"
    xmlns:common="using:Expenses.Common"
    xmlns:converters="using:Expenses.Converters" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <CollectionViewSource x:Name="ExpenseReportsViewSource"/>
        <CollectionViewSource x:Name="GroupedExpenseReportsViewSource" 
                              IsSourceGrouped="True" />
        <CollectionViewSource x:Name="GroupedExpenseReportsSemanticOut"/>

        <converters:DateTimeToStringConverter x:Key="DateTimeToStringConverter"/>
        <converters:DoubleToCurrencyStringConverter x:Key="DoubleToCurrencyStringConverter"/>

        <DataTemplate x:Key="ExpenseReportTemplate">
            <StackPanel Background="{StaticResource ItemTemplateBackgroundColor}"
                        Height="225"
                        Width="325"
                        HorizontalAlignment="Left" 
                        VerticalAlignment="Top">
                <TextBlock Text="{Binding Purpose}" 
                           Margin="20,15,0,0"
                           FontSize="22" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                           Margin="20,20,0,0"
                           FontSize="22" 
                           FontWeight="Bold" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <StackPanel Orientation="Horizontal"
                            Margin="20,20,0,0">
                    <TextBlock Text="Submitted on"
                               FontSize="20" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                    <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToStringConverter}}" 
                               Margin="5,0,0,0" 
                               FontSize="20" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal"
                            Margin="20,20,0,0">
                    <TextBlock Text="Approved on"
                               FontSize="20" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                    <TextBlock Text="{Binding DateResolved, Converter={StaticResource DateTimeToStringConverter}}" 
                               Margin="5,0,0,0" 
                               FontSize="20" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="SnappedExpenseReportTemplate">
            <StackPanel Background="{StaticResource ItemTemplateBackgroundColor}"
                        Height="225"
                        Width="260"
                        HorizontalAlignment="Left" 
                        VerticalAlignment="Top">
                <TextBlock Text="{Binding Purpose}" 
                           Margin="10,15,0,0"
                           FontSize="18" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                           Margin="10,20,0,0"
                           FontSize="18" 
                           FontWeight="Bold" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <StackPanel Orientation="Horizontal"
                            Margin="10,20,0,0">
                    <TextBlock Text="Submitted on"
                               FontSize="18" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                    <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToStringConverter}}" 
                               Margin="5,0,0,0" 
                               FontSize="18" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal"
                            Margin="10,20,0,0">
                    <TextBlock Text="Approved on"
                               FontSize="18" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                    <TextBlock Text="{Binding DateResolved, Converter={StaticResource DateTimeToStringConverter}}" 
                               Margin="5,0,0,0" 
                               FontSize="18" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="SemanticZoomOutItem">
            <StackPanel Background="{StaticResource ItemTemplateBackgroundColor}"
                        Width="300" 
                        Height="250">
                <TextBlock Text="{Binding Key}" 
                           Grid.Row="0"
                           Grid.Column="1"
                           Margin="20,50,0,0" 
                           VerticalAlignment="Top"
                           HorizontalAlignment="Left"
                           FontSize="{StaticResource FontSizeXLarge}"
                           FontWeight="SemiBold"/>
                <TextBlock Text="{Binding Summary}" 
                           Margin="20,50,0,0" 
                           VerticalAlignment="Top"
                           FontSize="{StaticResource FontSizeLarge}"
                           FontWeight="SemiBold"/>
            </StackPanel>
        </DataTemplate>

    </Page.Resources>

    <Grid x:Name="LayoutRoot" 
          Background="{StaticResource AppBackgroundColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border Background="{StaticResource ItemTemplateBackgroundColor}">
                <Button x:Name="BackButton" 
                        Click="BackButton_Click" 
                        Style="{StaticResource BackButtonStyle}"/>
            </Border>
            <Border Background="{StaticResource ItemTemplateBackgroundColor}"
                    Grid.Column="1" >
                <TextBlock x:Name="PageTitleTextBlock" 
                           Text="Charges"
                           Style="{StaticResource PageHeaderTextStyle}"
                           TextWrapping="Wrap"
                           FontSize="44"/>
            </Border>
        </Grid>

        <ProgressRing x:Name="ExpenseReportsHistoryProgressRing" 
                      Grid.Row="1" 
                      Height="150"
                      Width="150"
                      IsActive="False"/>

        <SemanticZoom x:Name="ExpenseReportsSemanticZoomer"
                      Grid.Row="1"
                      Margin="120,20,0,0"
                      Height="Auto"
                      Width="Auto">
            <SemanticZoom.ZoomedInView>
                <GridView x:Name="ExpenseReportsGridView" 
                          Width="Auto" 
                          Height="Auto"
                          ItemsSource="{Binding Source={StaticResource GroupedExpenseReportsViewSource}}"
                          SelectionMode="None"    
                          IsSwipeEnabled="False"
                          IsItemClickEnabled="True" 
                          ItemClick="ExpenseReportsGridView_ItemClick"
                          ItemTemplate="{StaticResource ExpenseReportTemplate}">
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Key}" 
                                                   FontSize="{StaticResource FontSizeLarge}"
                                                   Style="{StaticResource TextBlockGroupTitle}" />
                                        <TextBlock Text="("
                                                   FontSize="{StaticResource FontSizeLarge}"
                                                   Style="{StaticResource TextBlockGroupTitle}" 
                                                   Margin="10,0,0,0"/>
                                        <TextBlock Text="{Binding Summary}" 
                                                   Grid.Row="1"
                                                   VerticalAlignment="Top"
                                                   FontSize="{StaticResource FontSizeLarge}"
                                                   Style="{StaticResource TextBlockGroupTitle}" />
                                        <TextBlock Text=")"
                                                   FontSize="{StaticResource FontSizeLarge}"
                                                   Style="{StaticResource TextBlockGroupTitle}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <VariableSizedWrapGrid Orientation="Vertical" 
                                                           Margin="0,0,80,0" />
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </GridView.GroupStyle>
                </GridView>
                <!--  end grouped view -->
            </SemanticZoom.ZoomedInView>
            <SemanticZoom.ZoomedOutView>
                <GridView Foreground="White"     
                          SelectionMode="None"
                          ItemsSource="{Binding Mode=OneWay, Source={StaticResource GroupedExpenseReportsSemanticOut}}" 
                          ItemTemplate="{StaticResource SemanticZoomOutItem}">
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid ItemWidth="300" 
                                      ItemHeight="250" 
                                      MaximumRowsOrColumns="1" 
                                      VerticalChildrenAlignment="Top" />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.ItemContainerStyle>
                        <Style TargetType="GridViewItem">
                            <Setter Property="Margin" Value="4" />
                            <Setter Property="BorderBrush" Value="Gray" />
                            <Setter Property="BorderThickness" Value="1" />
                            <Setter Property="HorizontalContentAlignment" Value="Center" />
                            <Setter Property="VerticalContentAlignment" Value="Top" />
                        </Style>
                    </GridView.ItemContainerStyle>
                </GridView>
            </SemanticZoom.ZoomedOutView>
        </SemanticZoom>

        <ListView x:Name="ExpenseReportsListView"
                  AutomationProperties.AutomationId="ExpenseReportsListView"
                  AutomationProperties.Name="Grouped Items"
                  Grid.Row="1"
                  Width="300"
                  Visibility="Collapsed"
                  Margin="15,0,0,0"
                  ItemsSource="{Binding Source={StaticResource ExpenseReportsViewSource}}"
                  ItemTemplate="{StaticResource SnappedExpenseReportTemplate}"
                  SelectionMode="Multiple"
                  IsSwipeEnabled="True"
                  IsItemClickEnabled="True"
                  ItemClick="ExpenseReportsGridView_ItemClick">
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleStackPanel" 
                                                       Storyboard.TargetProperty="Orientation">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ReportsSummaryTextBlock" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,20,0,10"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackButton" 
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="FontSize">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="20"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="FontWeight">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="SemiBold"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpenseReportsGridView" 
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpenseReportsListView" 
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpenseReportsListView" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="15,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
